<template>
  <TCollapse title="是否正常损耗">
    <p style="color: red; margin-bottom: 25px">
      物资类订单无实物调减，金额总和≥500元时，本次项目特别修正申请为“非正常损耗”；否则，由申请人选择属于“正常损耗”还是“非正常损耗”。
    </p>
    <p style="color: red">
      【注意】“正常损耗”的项目特别修正申请，物资类订单无实物调减，仓储系统无需进行退库！
    </p>
    <MyForm ref="formRef" v-model="queryParams" :form-option="formOption" :select-list="dicLists" />
  </TCollapse>
</template>

<script>
import MyForm from "@/components/basic/myForm";
import { Mixins } from "@/views/speciaCorrection/minix";
import { getSpecialDetail } from "@/api/speciaCorrection/index";
export default {
  name: "SpecialWastage",
  components: { MyForm },
  mixins: [Mixins],
  watch: {
    newPrjDetail: {
      handler(val) {
        if (JSON.stringify(val) !== "{}") {
          this.getSpecialInfo();
        }
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
    showOperate() {
      return this.newWorkDetail?.activityDefID !== 'correct_01'
    }
  },
  data() {
    return {
      queryParams: {},
      dicLists: {
        WASTAGE_TYPE: [
          {
            dictId: "1",
            dictName: "正常损耗",
          },
          {
            dictId: "0",
            dictName: "非正常损耗",
          },
        ],
      },
      formOption: {
        size: "mini",
        inline: true,
        labelWidth: "160px",
        itemData: [
          {
            type: "select",
            prop: "isNormalloss",
            value: '',
            width: "",
            colSpan: 6,
            label: "是否正常损耗：",
            dicType: "WASTAGE_TYPE",
            clearable: true,
            disabled: false,
            rule: [{ required: true, message: "请选择该项是否为正常损耗" }],
            dicProp: {
              label: "dictName",
              value: "dictId",
            },
          },
        ],
      },
    };
  },
  methods: {
    async getSpecialInfo() {
      const params = {
        prjId: "",
        adjustId:
          this.newWorkDetail?.bizObject?.bizSeq || this.$route.query.adjustId,
      };
      const { code, data } = await getSpecialDetail(params);
      if (+code === 200) {
        this.formOption.itemData.forEach((item) => {
          item.value = data.isNormalloss || '1'
        })
        if (this.$refs.formRef !== undefined) {
          this.$refs.formRef.initData(this.formOption)
        }
      }
    },
    submit() {
      return {
        code: this.queryParams.isNormalloss ? "200" : "500",
        message: this.queryParams.isNormalloss ? "" : "请选择该项目是否为正常损耗！",
      };
    },
  },
  created() {
    this.formOption.itemData.forEach((item) => {
      item.disabled = this.showOperate;
    })
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-form-item__error {
  display: none !important;
}
</style>
<style>
.el-select-dropdown__item {
  width: 100% !important;
}
</style>
